package fencer911;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;


import javax.swing.*;
import java.awt.*;

/**
 * <pre>
 * 主界面
 * </pre>
 *
 * @author <a href="https://github.com/fencer911/transfer-file-by-qrcode">transfer-file-by-qrcode</a>
 * @since 2020/03
 */

public class MainWindow {
    private JTabbedPane tabbedPane;
    private JPanel mainPanel;
    private static MainWindow mainWindow;


    private JPanel qrCodeSenderPanel;
    private JPanel qrCodeReceiverPanel;


    public JPanel getQrCodeSenderPanel() { return qrCodeSenderPanel; }
    public JPanel getQrCodeReceiverPanel() { return qrCodeReceiverPanel; }

    public JTabbedPane getTabbedPane() {
        return tabbedPane;
    }
    public JPanel getMainPanel() {
        return mainPanel;
    }

    private MainWindow() {
    }

    public static MainWindow getInstance() {
        if (mainWindow == null) {
            mainWindow = new MainWindow();
        }
        return mainWindow;
    }

    private static GridConstraints gridConstraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false);

    public void init() {
        mainWindow = getInstance();
        mainWindow.getMainPanel().updateUI();

        mainWindow.getQrCodeSenderPanel().add(FileQrCodeSenderForm.getInstance().getRootPanel(), gridConstraints);
        mainWindow.getQrCodeReceiverPanel().add(FileQrCodeReceiverForm.getInstance().getRootPanel(), gridConstraints);

        mainWindow.getMainPanel().updateUI();
    }

    public void initForms(){
        FileQrCodeSenderForm.getInstance();
        FileQrCodeReceiverForm.getInstance();
    }
    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        tabbedPane = new JTabbedPane();
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.add(tabbedPane, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false));

        qrCodeSenderPanel = new JPanel();
        qrCodeSenderPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        tabbedPane.addTab("Generate",  qrCodeSenderPanel);

        qrCodeReceiverPanel = new JPanel();
        qrCodeReceiverPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        tabbedPane.addTab("Recognition", qrCodeReceiverPanel);

    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return mainPanel;
    }

}
